package Gantry::Samples::AuthCookie;

use strict;
use Gantry::Utils::HTML qw( :all );
use base 'Gantry::Samples';

sub init {
    my( $self, $r ) = @_;

    # process SUPER's init code
    $self->SUPER::init( $r );
    
    $self->auth_file( 'app.htpasswd' );
        
    # AuthCookie is envoked post_init so you can modify either 
    # auth_deny somewhere in the init or you can set it via conf.
    if ( $self->uri =~ /^\/authcookie\/closed$/ ) {
        $self->auth_deny( 'yes' );        
    }
    
}

#-----------------------------------------------------------------
# $self->do_main(  )
#-----------------------------------------------------------------
sub do_main {
    my $self = shift;
    
    $self->stash->view->title( 'Auth Cookie' );
    $self->template( 'authcookie.tt' );
    
}

#-----------------------------------------------------------------
# $self->do_open(  )
#-----------------------------------------------------------------
sub do_open {
    my ( $self ) = @_;
    
    return( "you're in" );

} # END do_open

#-----------------------------------------------------------------
# $self->do_closed(  )
#-----------------------------------------------------------------
sub do_closed {
    my ( $self ) = @_;
    
    my @lines;
    push( @lines, "you're in: " . $self->user );
    push( @lines,
        ht_br(), ht_br(),
        ht_a( 
            ( $self->app_rootp . "/login?logout=1" ),
            ('logout ' . $self->user), 
        ), 
    );
    return( join( "", @lines ) );

} # END do_closed

1;

=head1 NAME

Gantry::Samples::AuthCookie - A controller in the Gantry::Samples application

=head1 SYNOPSIS

This package is meant to be used in a stand alone server/CGI script or the
Perl block of an httpd.conf file.

Stand Alone Server or CGI script:

    use Gantry::Samples::AuthCookie;

    my $cgi = Gantry::Engine::CGI->new( {
        config => {
            #...
        },
        locations => {
            '/someurl' => 'Gantry::Samples::AuthCookie',
            #...
        },
    } );

httpd.conf:

    <Perl>
        # ...
        use Gantry::Samples::AuthCookie;
    </Perl>

    <Location /someurl>
        SetHandler  perl-script
        PerlHandler Gantry::Samples::AuthCookie
    </Location>

If all went well, one of these was correctly written during app generation.

=head1 DESCRIPTION

This module was originally generated by Bigtop.  But feel free to edit it.
You might even want to describe the table this module controls here.

=head1 METHODS

=over 4

=item do_open

=item do_closed

=item schema_base_class

=item get_orm_helper


=back


=head1 DEPENDENCIES

    Gantry::Samples

=head1 AUTHOR

Timotheus Keefer, E<lt>tkeefer@apple.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2006 Timotheus Keefer

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.

=cut
